package Util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class TestUtil {

	static Scanner scanner = new Scanner(System.in);

	/**
	 * 判断int类型输入是否合法
	 * 
	 * @return
	 */
	public static int abnormal() {
		int key = 0;
		try {
			key = Integer.parseInt(scanner.nextLine());
			if(key <= 0) {
				System.out.print("请输入大于0的整数：");
				key = abnormal();
			}
		} catch (Exception e) {
			System.out.print("输入错误，请重新输入：");
			key = abnormal();
		}
		return key;
	}


	/**
	 * 获得当前时间
	 * 
	 * @return
	 */
	public static String time() {
		long currentTime = System.currentTimeMillis();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
		Date date = new Date(currentTime);
		String time = formatter.format(date);

		return time;
	}
}
